<?php

namespace App\Observers;

use App\Models\Fang;
use App\server\EsServer;
use App\server\RedisServer;

class FangObserver
{
    /**
     * Handle the Fang "created" event.
     *
     * @param  \App\Models\Fang  $fang
     * @return void
     */
    public function created(Fang $fang)
    {
        $Es=new EsServer();
        $Es->EsAdd('fang',$fang->toArray());
        $redis=RedisServer::createRedisObject();
        $redis->select(15);
        $data=$fang->toArray();
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the Fang "updated" event.
     *
     * @param  \App\Models\Fang  $fang
     * @return void
     */
    public function updated(Fang $fang)
    {
        $data= $fang->toArray();
        $redis=RedisServer::createRedisObject();
        $redis->select(15);
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }
    /**
     * Handle the Fang "deleted" event.
     *
     * @param  \App\Models\Fang  $fang
     * @return void
     */
    public function deleted(Fang $fang)
    {
        //
    }

    /**
     * Handle the Fang "restored" event.
     *
     * @param  \App\Models\Fang  $fang
     * @return void
     */
    public function restored(Fang $fang)
    {
        //
    }

    /**
     * Handle the Fang "force deleted" event.
     *
     * @param  \App\Models\Fang  $fang
     * @return void
     */
    public function forceDeleted(Fang $fang)
    {
        //
    }
}
